<template>
  <div class="login_container">

    <van-date-picker
      v-model="currentDate"
      title="选择日期"
      :min-date="minDate"
      :max-date="maxDate"
    />
    
  </div>
</template>

<script>
import { createNamespacedHelpers, mapMutations } from 'vuex';
let { mapActions} = createNamespacedHelpers('public');

export default {
  name: 'login',
  data() {
    return {
      currentDate: '',
      
    };
  },
  created() {
  },

  mounted() {
    // this.submitForm();
  },


  methods: {
    ...mapActions(["post", "gisPost", "getMenuList"]),
    ...mapMutations(["updateInfo"]),

    // encrypt(data, key) {
    //   var encrypted = this.$CryptoJS.AES.encrypt(data, this.$CryptoJS.enc.Utf8.parse(key), {
    //     mode: this.$CryptoJS.mode.ECB,
    //     padding: this.$CryptoJS.pad.Pkcs7,
    //   }).toString();

    //   return encrypted;
    // },


    
    async getMenued() {
      const menuList = await this.getMenuList();
      let uri = '';
      if(!menuList[0].childrenMenu[0].childrenMenu) {
        uri = menuList[0].childrenMenu[0].uri
      }else {
        uri = menuList[0].childrenMenu[0].childrenMenu[0].uri
      }
      // if(menuList[0].uri == 'digitalMine' || !menuList[0].childrenMenu) {
      //   uri = menuList[0].uri
      // }else {
      //   if(!menuList[0].childrenMenu[0].childrenMenu) {
      //     uri = menuList[0].childrenMenu[0].uri
      //   }else {
      //     uri = menuList[0].childrenMenu[0].childrenMenu[0].uri
      //   }
      // }
      this.$router.push({ name: uri });
    },

    submitForm() {
      let data = {
        userName: this.$encrypt(this.loginForm.userName, 'zhuxue6789xuezhu'),
        passWord: this.$encrypt(this.loginForm.passWord, 'zhuxue6789xuezhu'),
        loginType: this.loginForm.loginType,
      };

      let API;
      
      switch (this.loginForm.loginType) {
        case '平台':
          API = 'adminLogin'
          break;
      
        case '商家':
          API = 'frontLogin'
          break;
      
        default:
          break;
      }


      

      if(!data.userName) {
        this.$message.error('请输入用户名');
        return false;
      }

      if(!data.passWord) {
        this.$message.error('请输入密码');
        return false;
      }
      
      this.btnLoading = true;
      
      this.post({
        API: API,
        data: data
      })
        .then(res => {
          let author_token = res.author_token;
          let jwtAuth = res.jwtAuth;
          // let loginTime = this.$dateFormat(Date.parse(new Date()),'yyyy/MM/dd HH:mm');
          localStorage.setItem('jwtAuth', jwtAuth);
          localStorage.setItem('author_token', author_token);
          // localStorage.setItem("loginTime", loginTime);

          // 开发完解除
          this.getMenued();
          // this.$router.push({ name: 'userManagement' });
        })
        .catch(err => {
          this.$message.error(err);
          this.btnLoading = false;
        });
    },

    
  }
};
</script>

<style lang="less" scoped>



</style>

